import Api from '@jiess/http';
import data from './data/index.js';
import {
  requestFunc,
  responseErrorFunc,
  responseSuccessFunc,
} from './interceptor.js';
const services1 = {
  development: 'http://xxx/api/module',
  proxy: 'http://xxx/api/module',
  test: 'http://xxx/api/module',
  production: 'http://xxx/api/module',
};

export const httpBaseConfig = {
  timeout: 5000,
  interceptors: {
    responseSuccess: responseSuccessFunc,
    responseError: responseErrorFunc,
    request: requestFunc,
  },
  customFetch: async (a, b) => {
    await new Promise((resolve) => {
      setTimeout(resolve, 500);
    });
    const response = await data(a, b);
    return {
      text: () =>
        JSON.stringify({
          code: 200,
          msg: '成功',
          data: response,
        }),
    };
  },
};

export const httpConfig1 = {
  baseURL: services1[process.env.NODE_ENV],
  ...httpBaseConfig,
};
export const api1 = new Api(httpConfig1);
